1. Field of the Invention
The present invention relates to programming languages. More specifically, the present invention relates to a method and an apparatus for implementing string objects defined within a programming language.
2. Related Art
Dramatic advances in computer technology presently make it possible to integrate a significant amount of computing power onto “smart cards.” Smart cards are presently used in a variety of applications that solve common security and identity needs. For example, smart cards have been integrated into credit cards, debit cards, corporate badges, and even cell phones.
New smart card designs can accommodate larger amounts of memory, for example, new smart card designs can accommodate up to 160K bytes of read-only memory (ROM), 64K bytes of electrically erasable programmable read-only memory (EEPROM), and 8K bytes of random access memory (RAM). These larger amounts of memory make it possible to integrate more functionality into a smart card. In particular, the additional memory can be used to implement a virtual machine, such as the JAVA™ virtual machine (JVM), in a smart card, and to allow the use of objects defined within an object-oriented programming system. (JAVA is a trademark of SUN Microsystems, Inc. of Santa Clara, Calif.) Integrating a virtual machine into a smart card enables the smart card execute a large number of platform-independent applications. Moreover, the associated development environment for the virtual machine can simplify the process of developing applications for smart cards.
While it is possible to implement a virtual machine on one of these smart cards, the memory is still quite limited compared to a typical desktop computer system. This limited memory leads to many challenges in the implementing an object-oriented programming system.
For example, FIG. 1 depicts an implementation of a string object as commonly implemented in the JAVA programming language. This implementation includes two parts: a string object 102 and a character array 114. Note that strings may be represented in this manner in programming languages and systems other than “object-oriented” systems.
String object 102 includes a class pointer 104, an array pointer 106, an offset 108, and a length 110. Class pointer 104 points to string class 112 and thereby identifies string object 102 as belonging to string class 112. Array pointer 106 points to the beginning of array of characters 122 within character array 114. Offset 108 points to the beginning of a sub-string 124 within array of characters 122. Finally, length 110 specifies the length of sub-string 124.
Character array 114 includes a length 116, a class pointer 118, and an array of characters 122. Class pointer 118 points to character class 120, which indicates that the object is a character array 114. Typically, characters in character array 114 are stored as sixteen-bit UNICODE™ characters. UNICODE is a trademark or registered trademark of UNICODE, Inc. Length 116 describes the length of the string in array of characters 122.
The implementation described above requires a minimum of twenty-eight bytes to store a single character-sixteen for string object 102 and twelve for character array 114. While using this amount of storage on a desktop machine with large amounts of memory might be acceptable, using this amount of storage on a small computing device, such as a smart card, or a computing device such as a web server that handles a large number of strings, needlessly reduces the available memory on these devices.
Hence, what is needed is a method and an apparatus for implementing string objects in a programming language without using an excessive amount of memory.